package com.javacoo.xservice.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.javacoo.xservice.base.AbstractParamController;
import com.javacoo.xservice.base.exception.IllegalParameterException;
import com.javacoo.xservice.base.support.AbstractAssert;
import com.javacoo.xservice.example.bean.vo.BaseReq;
import com.javacoo.xservice.example.constant.ErrorCodeConstants;
import com.javacoo.xservice.example.service.ExampleService;

import lombok.extern.slf4j.Slf4j;

/**
 * 获取案例数据接口,带参数
 * <p>说明:</p>
 * <li></li>
 * @author DuanYong
 * @since 2017年7月17日上午9:02:56
 */
@Slf4j
@RestController
@RequestMapping(value = "/example/v1/getExampleInfo")
public class ExampleController extends AbstractParamController<BaseReq> {
	/** 数据服务 */
	@Autowired
	private ExampleService exampleService;
	@Override
	protected void validate(BaseReq p) throws IllegalParameterException {
		AbstractAssert.notNull(p, ErrorCodeConstants.SERVICE_REQ_PARAM);
		AbstractAssert.isNotBlank(p.getId(), ErrorCodeConstants.SERVICE_GET_EXAMPLE_INFO_ID);
	}

	@Override
    //@ApiLock(fieldName = {"id"},paramIndex = 1,timeInSecond = 10)
	public Object process(BaseReq p) {
	    log.info("执行业务方法");
        return exampleService.getExampleInfo(p.getId()).get();
	}

	@Override
	protected Class<BaseReq> getParamClass() {
		return BaseReq.class;
	}
}
